#include <stdio.h>

//编译：gcc -o run_linear_function_fitting_v1 linear_function_fitting_v1.c
//编译运行：gcc -o bin/run_linear_function_fitting_v1 c/linear_function_fitting_v1.c && ./bin/run_linear_function_fitting_v1

// 函数声明
void calculate_linear_function(double points[3][2], double coefficients[2]);

int main() {
    // 输入的三个点
    double points[3][2] = {
        {35658, 9.808}, // 点1
        {67369, 15.67}, // 点2
        {78092, 19.261999}  // 点3
    };
    
    // 用于存储线性函数的系数a和b
    double coefficients[2] = {0, 0};

    // 调用函数计算系数
    calculate_linear_function(points, coefficients);

    // 打印结果
    printf(">>> 函数表达式: y = %fx + %f \r\n",coefficients[0], coefficients[1]);

    return 0;
}

// 计算线性函数的系数
void calculate_linear_function(double points[3][2], double coefficients[2]) {
    // 计算斜率 a
    double a = (points[2][1] - points[0][1]) / (points[2][0] - points[0][0]);

    // 计算截距 b
    double b = points[0][1] - a * points[0][0];

    // 存储系数
    coefficients[0] = a;
    coefficients[1] = b;
}
